package org.bangumibuddy.security.entity;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.security.authentication.AbstractAuthenticationToken;
import org.springframework.security.core.GrantedAuthority;

import javax.security.auth.Subject;
import java.util.Collection;

public class BangumiAuthenticationToken extends AbstractAuthenticationToken {

    private String userName;

    private String email;

    private String token;

    private String role;

    private String password;


    public static BangumiAuthenticationToken unauthenticated(String username, String password) {
       BangumiAuthenticationToken bangumiAuthenticationToken = new BangumiAuthenticationToken();
        bangumiAuthenticationToken.setUserName(username);
        bangumiAuthenticationToken.setPassword(password);

       return bangumiAuthenticationToken;
    }

    public static BangumiAuthenticationToken unauthenticated(String token) {
        BangumiAuthenticationToken bangumiAuthenticationToken = new BangumiAuthenticationToken();
        bangumiAuthenticationToken.setToken(token);
        return bangumiAuthenticationToken;
    }

    @Override
    public Object getCredentials() {
        return userName;
    }

    @Override
    public Object getPrincipal() {
        return password;
    }

    @Override
    public boolean implies(Subject subject) {
        return super.implies(subject);
    }

    public BangumiAuthenticationToken(Collection<? extends GrantedAuthority> authorities) {
        super(authorities);
    }

    public BangumiAuthenticationToken(){
        super(null);
        setAuthenticated(false);
    }

   public String getToken() {
        return token;
    }

    public void setToken(String token) {
        this.token = token;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getRole() {
        return role;
    }

    public void setRole(String role) {
        this.role = role;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
}
